﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using AirlineBooking.Models;

namespace AirlineBooking.Controllers
{
    public class TestController : Controller
    {
        //
        // GET: /Test/

        public ActionResult Index()
        {
            return View();
        }

        public ActionResult FindIntinerary(string dep, string des, int adult, int child, int infant, DateTime departDate)
        {
            return View(new RouteModel().findIntineraryOptions(dep, des, departDate, adult, child, infant));
        }

        public ActionResult FindRoute(string dep, string des)
        {
            using (AirLineDBModelEntities db = new AirLineDBModelEntities())
            {
                AirPort depPort = db.AirPorts.FirstOrDefault(i => i.Code == dep);
                AirPort desPort = db.AirPorts.FirstOrDefault(i => i.Code == des);
                List<List<string>> result = new List<List<string>>();
                if (dep == null || des == null)
                {
                    result = new List<List<string>>();
                }
                else
                {
                    result = new RouteModel().findRoutes(db, depPort, desPort);
                }
                return View(result);
            }
        }
    }
}
